<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>6.$watch</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../../js/vue.js"></script>
    <style>
      img {
        width: 100px;
      }
    </style>
  </head>
  <body>
    <!-- 准备好一个容器-->
    <div id="demo">
      <h1>今天天气很{{isHot ? '炎热' : '凉爽'}}</h1>
      <img :src="url" alt=""> <br>
      <button @click="isHot = !isHot">切换天气</button>
    </div>

    <script type="text/javascript">
      const vm = new Vue({
        el:'#demo',
        data:{
          isHot:true,
          url:'http://49.232.112.44/images/hot.jpg'
        },
      })

      setTimeout(() => {
        vm.$watch('isHot',function(value){
          if(value){
            this.url = 'http://49.232.112.44/images/hot.jpg'
          }else{
            this.url = 'http://49.232.112.44/images/cool.jpg'
          }
        })
      }, 3000);
    </script>
  </body>
</html>